TOOL CALL HEADER NOT WORKING (UNABLE TO AUTHORIZE ...
# support
c
@Vapi I am facing he same issue I add the authorization header with value as I also tried x-vapi-secret It doesn't work Here is the command i am using but I still keep getting 401 error
Copy code
curl -X PATCH https://api.vapi.ai/tool/toolcallId \
-H "Authorization: Bearer vapiapikey" \
-H "Content-Type: application/json" \
-d '{
  "function": {
    "name": "toolcallname",
    "description": "some description",
    "parameters": {
      "type": "object",
      "properties": {}
    }
  },
  "server": {
    "url": "webhookurl",
    "timeoutSeconds": 30,
    "headers": {
      "x-vapi-secret": "Bearer API_KEY"
    }
  },
  "async": false
}'
Also fyi I have already tested my webhook like this an I was able to see the triggering affect onto my webhook receving end
Copy code
curl -X POST <server_url> \
-H "authorization: Bearer <API_KEY>" \
-H "Content-Type: application/json" \
-d '{
  "eventType": "test.event",
  "payload": {
    "message": {
      "toolCalls": [{
        "id": "test123",
        "function": {
          "name": "test_function",
          "arguments": {"test": "data"}
      }
      }]
    }
  }
}'
c
Hey can you please share the call ID?
c
I will share a couple 75ac1bef-ec62-4140-a903-6b6398fbd97c 10cfb072-6b65-48b7-b03f-315343420753 01859be2-9bba-460a-8e10-8306e1d12403 0deb8ae3-df64-4b9c-9263-16ed692f0003 27e779a2-8ed0-4c1a-a4b0-34dfcf09097a
c
Copy code
{
  "type": "tool-calls",
  "toolCalls": [
    {
      "id": "call_DE6TZISulSwOuVKDFQHZSoiW",
      "type": "function",
      "function": {
        "name": "getPractitionerByAssistantIdDev",
        "arguments": {}
      }
    }
  ],
  "toolCallList": [
    {
      "id": "call_DE6TZISulSwOuVKDFQHZSoiW",
      "type": "function",
      "function": {
        "name": "getPractitionerByAssistantIdDev",
        "arguments": {}
      }
    }
  ],
  "toolWithToolCallList": [
    {
      "type": "function",
      "function": {
        "name": "getPractitionerByAssistantIdDev",
        "parameters": {
          "type": "object",
          "properties": {}
        },
        "description": "Get practitioner information based on assistant ID"
      },
      "async": false,
      "server": {
        "url": "https://api.eu.svxxxxxx/msg",
        "headers": {
          "Authorization": "Bearer testsk_FDxxxxxxxxxxxxxxxhG.eu"
        },
        "timeoutSeconds": 30
      },
      "messages": [],
      "toolCall": {
        "id": "call_DE6TZISulSwOuVKDFQHZSoiW",
        "type": "function",
        "function": {
          "name": "getPractitionerByAssistantIdDev",
          "arguments": {}
        }
      }
    }
  ]
}
Hey clarkkent, we are sending the header set by you do let me know if this incorrect or you require further help!!
c
the problem is even if we send the header...it doesnt authenticate* via this process* and gives 401 error* but that doesnt happen ...when I make curl request directly rather than vapi doing it
even though the authorization field appears..here*
that was my original problem
c
Hey clarkkent, the headers are of request body because of this you get 401. You need to just pick those from body and then make the required subsequent request or validation.
c
canyou give an example CURL request PATCH request(I was trying modify a toolcall) so i was using this What should I edit here .... this is what I am doing at the moment It seems the the docs mentioned to give all custom headers in this way...so its possible that I might have confused
Copy code
curl -X PATCH https://api.vapi.ai/tool/toolcallId \
-H "Authorization: Bearer vapiapikey" \
-H "Content-Type: application/json" \
-d '{
  "function": {
    "name": "toolcallname",
    "description": "some description",
    "parameters": {
      "type": "object",
      "properties": {}
    }
  },
  "server": {
    "url": "webhookurl",
    "timeoutSeconds": 30,
    "headers": {
      "authorization": "Bearer API_KEY"
    }
  },
  "async": false
}'
c
Looking at the server implementation, the system automatically adds headers including authentication in the following order: \- Content-Type: application/json \- Custom headers from server.headers \- X-Vapi-Secret (if configured) \- Authorization (if authentication session exists) Here's the correct CURL request structure: curl -X PATCH \\ \-H "Authorization: Bearer YOUR_VAPI_API_KEY" \\ \-H "Content-Type: application/json" \\ \-d '{ "function": { "name": "toolcallname", "description": "some description", "parameters": { "type": "object", "properties": {} } }, "server": { "url": "webhookurl", "timeoutSeconds": 30, "headers": { "X-Custom-Header": "custom-value" # Any custom headers for your webhook } }, "async": false }'
Do let me know how it goes for you.
c
Copy code
curl -X PATCH https://api.vapi.ai/tool/toolcallId \
-H "Authorization: Bearer vapiapikey" \
-H "Content-Type: application/json" \
-d '{
  "function": {
    "name": "toolcallname",
    "description": "some description",
    "parameters": {
      "type": "object",
      "properties": {}
    }
  },
  "server": {
    "url": "webhookurl",
    "timeoutSeconds": 30,
    "headers": {
      "authorization": "Bearer API_KEY"
    }
  },
  "async": false
}'
Hi I tried above.. Its pretty much the same story Do I change the header names ? to something else I am under the assumption "X-Custom-Header" ---> means here the "authorization" key*
s
No @clarkkent it will be sent as its. Can you share any of the recent call ID where it's not working for you.
Copy code
export class Server {
  /**
   *
   * API endpoint to send requests to.
   */
  @IsString()
  @IsUrlWithHelpfulError({
    protocols: ['https', 'wss'],
    require_protocol: true,
  })
  @IsOptional()
  url: string;

  /**
   * This is the secret you can set that Vapi will send with every request to your server. Will be sent as a header called x-vapi-secret.
   *
   * Same precedence logic as server.
   */
  @Exclude({ toPlainOnly: true })
  @IsOptional()
  @IsString()
  secret?: string;

  /**
   * This is the timeout in seconds for the request to your server. Defaults to 20 seconds.
   *
   * @default 20
   */
  @IsOptional()
  @IsNumberWithHelpfulError()
  @Min(1)
  @Max(120)
  @ApiPropertyOptional({ example: 20 })
  timeoutSeconds?: number;

  /**
   * These are the custom headers to include in the request sent to your server.
   *
   * Each key-value pair represents a header name and its value.
   */
  @IsOptional()
  @IsObject()
  @IsReasonaleSizeWithHelpfulError({ maxLength: 100000 })
  headers?: Record<string, string>;

  /**
   * This is the backoff plan to use if the request fails.
   */
  @IsOptional()
  @IsObject()
  @ValidateNested()
  @Type(() => BackoffPlan)
  backoffPlan?: BackoffPlan;
}
c
@Shubham Bajaj here is the callId 4e140339-3b2a-40fa-9f7c-c1c31663f006
c
Hey @clarkkent, sorry for the delay. Can you check the call ID again? It doesn’t include any tool call where I can check if the secret was sent.